package ar.uba.fi.tp2Unit.displayers;

import java.io.FileWriter;
import java.io.IOException;

import ar.uba.fi.tp2Unit.framework.TestResult;
import ar.uba.fi.tp2Unit.framework.TestResultDisplayable;


/**
 * It writes the results of the execution of a test fixture
 * in a file.
 * 
 * @author grupo12
 * @see {@link TestResultDisplayable}
 */
public class FileTestResultDisplayer implements TestResultDisplayable {

	private String fileName;

	public FileTestResultDisplayer(String fileName) {
		this.fileName = fileName;
	}

	public void display(TestResult testResult) {		
			FileWriter resultFile;
			try {
				resultFile = new FileWriter(fileName);
				resultFile.write(testResult.toString() + "\r\n");
				resultFile.close();
			} catch (IOException e) {
				throw new FileWritingException(e.getMessage());
			}
	}
}
